package com.pkk.penguin.util.image.support.example;

import com.pkk.penguin.util.image.support.dto.ImageTextAttri;
import com.pkk.penguin.util.image.support.make.ImageEncodeText;
import com.pkk.penguin.util.image.support.utils.ImageStreamUtil;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import javax.imageio.ImageIO;
import org.apache.commons.lang3.StringUtils;

/**
 * @description: 简单用例
 * @author: peikunkun
 * @create: 2019-11-08 10:38
 **/
public class SimpleExample {

  public static void main1(String[] args) throws IOException {
    String srcImgPath = "https://fine-1257290547.cos.ap-hongkong.myqcloud.com/image/1537776468340jPnVnDQjZ5lxalJn.png";
    String tarImgPath = "C:\\Users\\Administrator\\Desktop\\target.png";
    ImageTextAttri imageTextAttriName = ImageTextAttri.builder().left(250).top(350).content("裴昆昆").build();

    ImageTextAttri imageTextAttriPhone = ImageTextAttri.builder().left(250).top(430).content("1234576543").build();

    ArrayList<ImageTextAttri> imageTextAttris = new ArrayList<>();
    imageTextAttris.add(imageTextAttriName);
    imageTextAttris.add(imageTextAttriPhone);

    URL url = new URL(srcImgPath);
    final BufferedImage read = ImageIO.read(url);
    final InputStream inputStream = ImageStreamUtil.bufferedImageToInputStream(read);
    final FileOutputStream fileOutputStream = new FileOutputStream(tarImgPath);
    new ImageEncodeText().makeImageText(inputStream, fileOutputStream, imageTextAttris);
    fileOutputStream.close();
  }


  public static void main(String[] args) throws MalformedURLException, FileNotFoundException {
    String tarImgPath = "C:\\Users\\Administrator\\Desktop\\target1.png";
    FileOutputStream fileOutputStream = new FileOutputStream(tarImgPath);
    BootMakeInvitationReqDTO bootMakeInvitationReqDTO = new BootMakeInvitationReqDTO();
    final ArrayList<ImageTextAttri> arrayList = new ArrayList<ImageTextAttri>();
    ImageTextAttri invitationName = ImageTextAttri.builder().left(250).top(350).content("裴昆昆").build();
    ImageTextAttri invitationTime = ImageTextAttri.builder().left(250).top(430).content("9月24日" + "-" + "下午2点").build();

    String interviewAddressStr = "";
    if (StringUtils.isBlank(bootMakeInvitationReqDTO.getInterviewAddress())) {
      interviewAddressStr = "地铁1/12/13号汉中路10号口出马路对面";
    } else {
      interviewAddressStr = bootMakeInvitationReqDTO.getInterviewAddress();
    }
    ImageTextAttri interviewAddress = ImageTextAttri.builder().left(250).top(510).content(interviewAddressStr)
        .font(new Font("楷体", Font.BOLD, 20)).build();

    String phoneStr = "";
    if (StringUtils.isBlank(bootMakeInvitationReqDTO.getPhone())) {
      phoneStr = "13253511485同微信~";
    } else {
      phoneStr = bootMakeInvitationReqDTO.getPhone();
    }

    ImageTextAttri phone = ImageTextAttri.builder().left(250).top(590).content(phoneStr).build();

    String invitationTeacherStr = "";
    if (StringUtils.isBlank(bootMakeInvitationReqDTO.getInvitationTeacher())) {
      invitationTeacherStr = "赵老师";
    } else {
      invitationTeacherStr = bootMakeInvitationReqDTO.getInvitationTeacher();
    }
    ImageTextAttri invitationTeacher = ImageTextAttri.builder().left(250).top(670).content(invitationTeacherStr)
        .build();
    String salaryAndWelfareStr1 = "";
    if (StringUtils.isBlank(bootMakeInvitationReqDTO.getSalaryAndWelfare())) {
      salaryAndWelfareStr1 = "无责底薪6000+餐补23元/天+提成";
    } else {
      salaryAndWelfareStr1 = bootMakeInvitationReqDTO.getSalaryAndWelfare();
    }
    ImageTextAttri salaryAndWelfare1 = ImageTextAttri.builder().left(250).top(740).content(salaryAndWelfareStr1)
        .font(new Font("楷体", Font.BOLD, 25)).build();

    String salaryAndWelfareStr2 = "";
    if (StringUtils.isBlank(bootMakeInvitationReqDTO.getSalaryAndWelfare())) {
      salaryAndWelfareStr2 = " （综合薪资一万二以上）";
    } else {
      salaryAndWelfareStr2 = bootMakeInvitationReqDTO.getSalaryAndWelfare();
    }
    ImageTextAttri salaryAndWelfare2 = ImageTextAttri.builder().left(240).top(770).content(salaryAndWelfareStr2)
        .font(new Font("楷体", Font.BOLD, 25)).build();
    String salaryAndWelfareStr3 = "";
    if (StringUtils.isBlank(bootMakeInvitationReqDTO.getSalaryAndWelfare())) {
      salaryAndWelfareStr3 = "员工享有行业最专业系统带薪培训";
    } else {
      salaryAndWelfareStr3 = bootMakeInvitationReqDTO.getSalaryAndWelfare();
    }
    ImageTextAttri salaryAndWelfare3 = ImageTextAttri.builder().left(240).top(800).content(salaryAndWelfareStr3)
        .font(new Font("楷体", Font.BOLD, 25)).build();
    String salaryAndWelfareStr5 = "";
    if (StringUtils.isBlank(bootMakeInvitationReqDTO.getSalaryAndWelfare())) {
      salaryAndWelfareStr5 = "公司团队年轻有活力、团建活动";
    } else {
      salaryAndWelfareStr5 = bootMakeInvitationReqDTO.getSalaryAndWelfare();
    }
    ImageTextAttri salaryAndWelfare5 = ImageTextAttri.builder().left(240).top(830).content(salaryAndWelfareStr5)
        .font(new Font("楷体", Font.BOLD, 25)).build();

    String salaryAndWelfareStr6 = "";
    if (StringUtils.isBlank(bootMakeInvitationReqDTO.getSalaryAndWelfare())) {
      salaryAndWelfareStr6 = "节假日、生日惊喜各种福利等着你";
    } else {
      salaryAndWelfareStr6 = bootMakeInvitationReqDTO.getSalaryAndWelfare();
    }
    ImageTextAttri salaryAndWelfare6 = ImageTextAttri.builder().left(240).top(860).content(salaryAndWelfareStr6)
        .font(new Font("楷体", Font.BOLD, 25)).build();

    arrayList.add(invitationName);
    arrayList.add(invitationTime);
    arrayList.add(interviewAddress);
    arrayList.add(phone);
    arrayList.add(invitationTeacher);
    arrayList.add(salaryAndWelfare1);
    arrayList.add(salaryAndWelfare2);
    arrayList.add(salaryAndWelfare3);
    arrayList.add(salaryAndWelfare5);
    arrayList.add(salaryAndWelfare6);
    ImageEncodeText imageEncodeText = new ImageEncodeText();
    String srcImgPath = "https://fine-1257290547.cos.ap-hongkong.myqcloud.com/image/1537776468340jPnVnDQjZ5lxalJn.png";
    imageEncodeText.makeImageText(new URL(srcImgPath), fileOutputStream, arrayList);
  }
}
